-- UnitTest
-- Create by weism
-- 单元测试

local zlib = require "zlib"
local lfs = require "lfs"

require "game/ui/base/util"

UnitTest = UnitTest or {};

function UnitTest.test()   
    if DEBUG_MODE ~= 1 then
        return;
    end
 
    trace("UnitTest", "**** 开始进行单元测试");
    Buffer.test();
    --LPC.test();
    
    --压缩测试
    local buf = zlib.compress("ABCDEFGABCDEFG", Z_BEST_SPEED)
    local b = Buffer.create(0);
    Buffer.setstr(b, 1, string.len(buf), buf);
    Buffer.set8(b, 2, 218);
    print(Buffer.toHex(b));
    local str = zlib.decompress(buf)
    print(str)
    
    --目录测试
    local iter, dir = lfs.dir(".")
    local file = dir:next()
    while file do
        file = dir:next()
        print(tostring(file))
    end
       
    -- 消息包测试
    PktAnalyser.test();
        
    --获取毫秒级时间
    local socket = require "socket"
    print(socket.gettime())
    
--    -- 测试内存泄露
--    local snapshot = require "snapshot";
--    local S1 = snapshot();
--    local tmp = {};
--    local S2 = snapshot();
--
--    for k,v in pairs(S2) do
--        if S1[k] == nil then
--            print(v);
--        end
--    end     
    
    trace("UnitTest", "**** 单元测试结束")
end


